Migrate azure-spring-data-cosmos tests from JUnit 4 to JUnit 5#47346
Migrate azure-spring-data-cosmos tests from JUnit 4 to JUnit 5#47346
Conversation
- Removed JUnit 4 and junit-vintage-engine dependencies from pom.xml - Migrated 85+ test files from JUnit 4 to JUnit 5 - Updated imports from org.junit to org.junit.jupiter.api - Replaced @Before/@after with @BeforeEach/@AfterEach - Replaced @BeforeClass/@afterclass with @BeforeAll/@afterall - Replaced @RunWith with @ExtendWith for Mockito and Spring - Replaced Assert with Assertions - Removed TestRule interface from AbstractIntegrationTestCollectionManager - Fixed static imports for AssertJ and JUnit Jupiter Remaining work: - Fix a few remaining compilation errors in 3 test files - Run full test suite to ensure all tests pass Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
- Successfully migrated all 85+ test files from JUnit 4 to JUnit 5 - All tests now compile successfully with JUnit 5 - Removed JUnit 4 and junit-vintage-engine dependencies - Updated all annotations and assertions - Fixed all import statements - Removed TestRule interface usage Remaining: 14 test failures to fix (mainly incorrect @test(expected=...) conversions) These tests expect exceptions but were incorrectly migrated from @test(expected=Exception.class) syntax Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
- Wrapped test bodies expecting exceptions with assertThrows() in CosmosTemplateUnitTest - Wrapped test bodies expecting IllegalQueryException with assertThrows() in CriteriaUnitTest - Wrapped all test bodies expecting IllegalArgumentException with assertThrows() in SimpleCosmosRepositoryIllegalTest - Used lenient() for unused stubbing in SimpleCosmosRepositoryUnitTest to fix UnnecessaryStubbing errors All 120 tests now pass successfully. Co-authored-by: Netyyyy <92105726+Netyyyy@users.noreply.github.com>
Removed junit and junit-vintage-engine dependencies.
|
/azp run java - spring - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR successfully migrates all tests in azure-spring-data-cosmos from JUnit 4 to JUnit 5 in preparation for Spring Boot 4 upgrade. The migration involves 85+ test files with comprehensive updates to annotations, imports, assertions, and test patterns.
Key Changes
- Removed JUnit 4 dependencies (
junit:junit4.13.2,junit-vintage-engine5.12.2) - Updated all test annotations from JUnit 4 to JUnit 5 equivalents
- Converted
@Test(expected=...)patterns toassertThrows()lambdas - Removed
@ClassRuleand@Ruleannotations along with TestRule interface implementation - Updated static imports for assertions and test utilities
Reviewed changes
Copilot reviewed 92 out of 92 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Removed JUnit 4 and vintage engine dependencies |
| external_dependencies.txt | Removed JUnit 4 dependency version references |
| 85+ test files | Migrated annotations, imports, and assertions from JUnit 4 to JUnit 5 |
| AbstractIntegrationTestCollectionManager.java | Removed TestRule interface implementation |
| SimpleCosmosRepositoryUnitTest.java | Added lenient() for Mockito stubbing |
|
Hi @kushagraThapar , we already check the changes, please help review it at your earliest convenience. |
Thanks @Netyyyy we need to run the cosmos spring tests in order to verify the changes as well. |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@Netyyyy I see few spring data cosmos tests failing here: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=5622303&view=ms.vss-test-web.build-test-results-tab&runId=58230383&resultId=100167&paneView=debug |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Hi @kushagraThapar , the tests passed, please help take a review, thanks. |
|
/check-enforcer override |
…#47346) - Removed JUnit 4 and junit-vintage-engine dependencies from pom.xml - Updated imports from org.junit to org.junit.jupiter.api - Replaced @Before/@after with @BeforeEach/@AfterEach - Replaced @BeforeClass/@afterclass with @BeforeAll/@afterall - Replaced @RunWith with @ExtendWith for Mockito and Spring - Replaced Assert with Assertions - Removed TestRule interface from AbstractIntegrationTestCollectionManager - Fixed static imports for AssertJ and JUnit Jupiter - Migrate @test(expected=...) to assertThrows (cherry picked from commit 7ced330)
* fix: suppress deprecation warnings for Spring Framework 7.0 @Nullable/@nonnull annotations * replace ListenableFutureCallback * add spring-boot-persistence and replace * fix ConfigurableBootstrapContext/EnvironmentPostProcessor path * replace with spring-boot-kafka * remove alwaysApplyingWhenNonNull() * replace with spring-boot-data-redis * replace with spring-boot-jms * replace with spring-boot-jdbc * add spring-boot-restclient * add spring-boot-security * add spring-boot-jackson * add spring-boot-http-converter * replace new OAuth2ClientAutoConfiguration * replace containsKey with containsHeader * add spring-boot-health * replace spring-boot-starter-web with spring-boot-starter-webmvc * replace org.springframework.data.util.TypeInformation with org.springframework.data.core.TypeInformation * replace with ParametersSource.of() * replace QueryMethodEvaluationContextProvider with ValueExpressionDelegate * replace ClassTypeInformation.from with TypeInformation.of * Migrate azure-spring-data-cosmos tests from JUnit 4 to JUnit 5 (#47346) * skip monitor for not support Spring Boot 4 * replace with jackson2 * replace spring.jms.listener.concurrency with spring.jms.listener.minConcurrency * Add jackson-databind
JUnit 4 to JUnit 5 Migration - COMPLETE ✅
Successfully migrated all tests in azure-spring-data-cosmos from JUnit 4 to JUnit 5 in preparation for Spring Boot 4 upgrade.
Migration Checklist
Changes
Dependencies (pom.xml)
junit:junit4.13.2 dependencyjunit-vintage-enginecompatibility layerTest Annotations & Imports (85+ files)
@Before/@After→@BeforeEach/@AfterEach@BeforeClass/@AfterClass→@BeforeAll/@AfterAll@Ignore→@Disabled@RunWith(MockitoJUnitRunner.class)→@ExtendWith(MockitoExtension.class)@RunWith(SpringJUnit4ClassRunner.class)→@ExtendWith(SpringExtension.class)org.junit.Assert→org.junit.jupiter.api.AssertionsCode Refactoring
TestRuleinterface implementation fromAbstractIntegrationTestCollectionManager@ClassRuleand@Ruleannotations@Test(expected=Exception.class)toassertThrows()patternlenient()for Mockito stubbings that are not used in all testsExample Conversion
Test Results
✅ All 120 tests passing
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.